$(document).ready(function(){
	// Declare classes
	MC.ExpenseSummaryModel = Backbone.Model.extend({
		defaults: {
			'yearspend': 0,
			'monthspend': 0,
			'todayspend': 0,
			'sevendayspend': 0
		}
	});
	
	MC.ExpenseSummaryView = Backbone.View.extend({
		el: '#summary',
		
		template: _.template($('#summary-tpl').html()),
		
		initialize: function() {
			_.bindAll(this, 'render');
			this.model.on('change', this.render);
		},
		
		render: function() {
			$(this.el).html(this.template(this.model.toJSON()));
			return this;
		}
	});
	
	
	// Construct widgets
	MC.expenseSummaryModel = new MC.ExpenseSummaryModel();
	MC.expenseSummaryView = new MC.ExpenseSummaryView({
		model: MC.expenseSummaryModel
	});
	MC.expenseSummaryView.render();
	
	// Request data from server
	$.get('/mpems/expense/viewSummary', function(data){
		MC.expenseSummaryModel.set(data);
	});
});